package m202405.d27;

import java.util.*;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/27 14:06
 */
public class Q4 {

    public static void main(String[] args) {
        Q4 q4 = new Q4();
        q4.findMedianSortedArrays(new int[]{2}, new int[]{});
    }


    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] array = new int[(nums1.length + nums2.length) / 2 + 1];
        int p1 = 0;
        int p2 = 0;
        for (int i = 0; i < array.length; i++) {
            if (p1 >= nums1.length) {
                array[i] = nums2[p2];
                p2++;
                continue;
            }
            if (p2 >= nums2.length) {
                array[i] = nums1[p1];
                p1++;
                continue;
            }
            if (nums1[p1] > nums2[p2]) {
                array[i] = nums2[p2];
                p2++;
            } else {
                array[i] = nums1[p1];
                p1++;
            }
        }
        if ((nums1.length + nums2.length) % 2 == 0) {
            return (array[array.length - 2] + array[array.length - 3]) / 2.0;
        } else {
            return array[array.length - 1];
        }
    }
}
